package com.ft.user.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.ft.user.domain.User;
import com.ft.user.repository.UserRepository;

@RestController
@RequestMapping("user")
public class UserServiceImpl implements UserService {
	private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
	
	@Autowired
    private UserRepository userRepository;
	
	@RequestMapping(value = "", method=RequestMethod.GET)
	@Override
	public List<User> getList() {
		List<User> list = userRepository.getList();
		logger.info("从数据库读取User集合:" + list);
		return list;
	}
	
	@RequestMapping(value = "/updateNameById", method=RequestMethod.POST)
	@Override
	public int updateNameById(String name, Long id) {
		logger.info("从数据库中更新id为"+id+"的名字:" + name);
		return userRepository.updateNameById(name, id);
	}
	@RequestMapping(value = "/save", method=RequestMethod.POST)
	@Override
	public User save(User user) {
		logger.info("保存对象到数据库:" + user);
		return userRepository.save(user);
	}

}
